package com.yanqu.road.server.cmd.strongholdwar;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.logic.pb.UnionBasePb;
import com.yanqu.road.pb.activity.StrongholdWarCrossProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.strongholdwar.StrongholdWarMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.math.BigInteger;

@Cmd(code = CrossProtocol.C_CROSS_STRONGHOLD_DONATE_SILVER, desc = "")
public class CrossStrongholdDonateSilverCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        StrongholdWarCrossProto.StrongholdCrossDonateSilverReqMsg reqMsg = StrongholdWarCrossProto.StrongholdCrossDonateSilverReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        long userId = reqMsg.getUserId();
        String unionId = reqMsg.getUnionId();
        BigInteger num = new BigInteger(reqMsg.getNum());
        UserBaseInfo userBaseInfo = PlayerBasePb.parseBaseUserInfo(reqMsg.getUserInfo());
        CrossUserMgr.updateUserBaseInfo(userId, userBaseInfo);
        UnionBaseInfo unionBaseInfo = UnionBasePb.parseUnionBaseInfo(reqMsg.getUnionInfo());
        StrongholdWarMgr.donateSilver(activityId, unionId, userId, num, userBaseInfo, unionBaseInfo);


    }

    @Override
    public void sendData() {

    }
}
